import { treeToArray } from './tree.js'

export function concatRoute(list, parent) {
  for (let i = 0; i < list.length; i++) {
    const item = list[i];
    if (parent) {
      item.path = parent.path + item.path
      item.name = parent.name + item.name
      item.meta.level = parent.meta.level + 1
    }
    if (item.children && item.children.length) {
      item.children = concatRoute(item.children, item)
    }
  }
  return list
}

export function getKeepAliveNames(routes) {
  let list = treeToArray(routes)
    .filter(item => item.meta && item.meta.keepAlive)
    .map(item => item.name);
  return list;
}